﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class AdminCMS_tab_Statistics_List : System.Web.UI.Page
{
    [RequestQuery.Query(QueryKey = "sdate")]
    public DateTime sdate = DateTime.MinValue; //起始日期
    [RequestQuery.Query(QueryKey = "edate")]
    public DateTime edate = DateTime.MinValue; //起始日期    
    [RequestQuery.Query(QueryKey = "keyword")]
    public string keyword = string.Empty;  //关键词
    [RequestQuery.Query(QueryKey = "fromurl")]
    public string fromurl = string.Empty;  //前地址
    [RequestQuery.Query(QueryKey = "tourl")]
    public string tourl = string.Empty;  //访问地址

    protected void Page_Load(object sender, EventArgs e)
    {
        RequestQuery.SetQueryValues();

        if (!IsPostBack)
        {
            txt_sdate.Text = (sdate == DateTime.MinValue) ? string.Empty : sdate.ToShortDateString();
            txt_edate.Text = (edate == DateTime.MinValue) ? string.Empty : edate.ToShortDateString();
            txt_keyword.Text = keyword;
            txt_FromURL.Text = fromurl;
            txt_ToURL.Text = tourl;

            ProSplitPage1.DataSource = GetPagingData();  //给分页控件附值
            ProSplitPage1.AppendQuery = RequestQuery.GetQueryValues();
            repeater1.DataSource = ProSplitPage1.SplitSource(); //返回拆分结果
            repeater1.DataBind();
        }
    }

    #region 分页方法

    public DataSet GetPagingData()
    {
        StringBuilder sql = new StringBuilder();
        sql.Append(
@"SELECT sta_FromURL,sta_ID,sta_IPAddress,sta_ToURL,sta_VisitDate
FROM [tab_Statistics] WHERE 1 = 1");
        /* 追加条件*/
        if (sdate != DateTime.MinValue)
        {
            sql.Append(" and sta_VisitDate >= #").Append(sdate.ToString("yyyy-MM-dd 00:00:00")).Append("#");
        }

        if (edate != DateTime.MinValue)
        {
            sql.Append(" and sta_VisitDate <= #").Append(edate.ToString("yyyy-MM-dd 23:59:59")).Append("#");
        }

        if (keyword != string.Empty)
        {
            sql.Append(" and sta_IPAddress like '%").Append(keyword).Append("%'");
        }

        if (fromurl != string.Empty)
        {
            sql.Append(" and sta_FromURL = '").Append(fromurl).Append("'");
        }

        if (tourl != string.Empty)
        {
            sql.Append(" and sta_ToURL = '").Append(tourl).Append("'");
        }

        string Primary = "sta_ID"; //主键
        string Orderby = Primary + " DESC";  //排序
        return DataEntity.Common.ExecuteSplitPage(sql.ToString(), Primary, Orderby, ProSplitPage1.MaxRows, ProSplitPage1.PageIndex);
    }
    #endregion
}
